# -*- coding: utf-8 -*-
from openerp.osv import fields
from openerp.osv import osv
from openerp import SUPERUSER_ID


class import_express_cost(osv.osv_memory):
    _name = 'import.express.cost.wizard'
    _inherit = ['import.wizard']

    def need_column_date_header(self, cr, uid, context=None):
        vals = [('express_code', u"快递单号"), ('express_cost', u"快递费用")]
        return vals

    def judge_and_write_vals(self, cr, uid, ids, data_dcit, context=None):
        cost_obj = self.pool.get('express.cost')
        cost_id = cost_obj.search(cr, uid, [('express_code', '=', data_dcit.get('express_code'))], context=context)
        if cost_id:
            cost_obj.write(cr, uid, cost_id, data_dcit, context=context)
        else:
            cost_obj.create(cr, uid, data_dcit, context=context)
        return True

    def return_vals_action(self, cr, uid, ids, this_id, context=None):
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'import.express.cost.wizard',
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': this_id,
            'views': [(False, 'form')],
            'target': 'new',
        }